/**
 * 多文件读取 
 */
const fs = require('fs');
//回调地狱的形式
// fs.readFile('./resource/1.html', (err, data1) => {
//     if(err) throw err;
//     fs.readFile('./resource/2.html', (err, data2) => {
//         if(err) throw err;
//         fs.readFile('./resource/3.html', (err, data3) => {
//             if(err) throw err;
//             console.log(data1 + data2 + data3);
//         });
//     })
// });

new Promise((resolve, reject) => {
    fs.readFile('./resource/1.html', (err, data) => {
        //如果失败 则修改promise对象状态为失败
        if(err) reject(err);
        //如果成功 则修改 promise 对象状态为成功
        resolve(data);
    });
}).then(value => {
    return new Promise((resolve, reject) => {
        fs.readFile('./resource/2.html', (err, data) => {
            //失败
            if(err) reject(err);
            //成功
            resolve([value, data]);
        });
    })
}).then(value => {
    return new Promise((resolve, reject) => {
        fs.readFile('./resource/3.html', (err, data) => {
            if(err) reject(err);
            // [data1, data2, data3]
            value.push(data);
            //设置成功
            resolve(value);
        })
    })
}).then(value => {
    console.log(value.join(''));
}).catch(reason => {
    console.log(reason);
});
